package com.fh.shop.api.exception;

import com.fh.shop.api.common.ResponseEnum;
import com.fh.shop.api.common.ServerResponse;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.sql.SQLException;

/**
 * 统一异常处理器【全局异常处理器】
 * 它会捕获指定的异常
 */
//@ControllerAdvice
//@ResponseBody
@RestControllerAdvice
public class WebExceptionHandler {

    @ExceptionHandler(TokenException.class)
    public ServerResponse handleTokenException(TokenException e) {
        ResponseEnum responseEnum = e.getResponseEnum();
        return ServerResponse.error(responseEnum);
    }


}
